#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    int num, *cycle, cycle_length = 0;
    scanf(" %d", &num);
    cycle = (int*)malloc(sizeof(int) * num);
    for (int i = 0; i < num; i++) {
        scanf("%d", &cycle[i]);
        cycle_length += cycle[i];
    }

    int times, start, end, distance;
    scanf(" %d", &times);
    for (int i = 0; i < times; i++) {
        distance = 0;
        scanf(" %d %d", &start, &end);
        if (start < end) 
            for (int j = start - 1; j < end - 1; j++)
                distance += cycle[j];
        if (start > end)
            for (int j = end - 1; j < start - 1; j++)
                distance += cycle[j];
            
        if (distance < cycle_length - distance)
            printf("%d\n", distance);
        else
            printf("%d\n", cycle_length - distance);
    }

    return 0;
}
